<?php

namespace app\index\model;

use think\Model;
use think\model\concern\SoftDelete;

class Blog extends Model
{
    //软删除
    use SoftDelete;
    protected $deletetime ='delete_time';
    /*
     * allselect前三条连表查询
     * fourselect从第四条开始的连表
     * sevenselect特别推荐
     * eightselect推荐文章
     * nineselect点击排行
     * blogselect每个分类模块
     * lifesevenselect生活的特别推荐
     * lifeeightselect生活的推荐文章
     * lifenineselect生活的点击排行
     */
    public function allselect(){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->limit(0,3)
            ->select();
    }
    public function fourselect(){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->limit(3,3)
            ->select();
    }
    public function sevenselect(){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->order('click desc')
            ->limit(1,1)
            ->select();
    }
    public function eightselect(){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->order('click desc')
            ->limit(2,1)
            ->select();
    }
    public function nineselect(){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->order('click desc')
            ->limit(0,1)
            ->select();
    }
    public function search(array $data){
        $date =$data['keyboard'];
        return Blog::where('name','like',"%$date%")->select();
    }
    public function blogselect($cid){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->where('cid',$cid)
            ->select();
    }
    public function lifesevenselect($cid){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->order('click desc')
            ->where('cid',$cid)
            ->limit(1,1)
            ->select();
    }
    public function lifeeightselect($cid){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->order('click desc')
            ->where('cid',$cid)
            ->limit(2,2)
            ->select();
    }
    public function lifenineselect($cid){
        return Blog::alias(['tp_cate'=>'c','tp_blog'=>'b'])
            ->field('b.*,c.title,c.content')
            ->join('tp_cate','c.id=b.cid')
            ->order('click desc')
            ->where('cid',$cid)
            ->limit(0,3)
            ->select();
    }
}
